﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace TongHopBookFlightCores.Cores
{
    public class AirMekongUtils
    {

        /// <summary>
        ///  Lấy danh sách điểm dừng 
        /// </summary>
        /// <param name="stopStation"></param>
        public static string GetStopStation(string stopStation)
        {
            int idxStart = stopStation.IndexOf("('");
            int idxStop = stopStation.IndexOf("',");
            int length = idxStop - idxStart;
            string result= stopStation.Substring(idxStart + 2, length- 2);

            return result;
        }

        /// <summary>
        /// Lấy mã chuyến bay
        /// </summary>
        /// <param name="codeFlight">Mã chuyến bay chưa chuẩn hóa chuỗi</param>
        public static string GetCodeFlight(string codeFlight)
        {
            string pattern = "\r\n";
            Regex myregex = new Regex(pattern);
            string ketqua = myregex.Replace(codeFlight, "");

            pattern = " ";
            myregex = new Regex(pattern);
            ketqua = myregex.Replace(ketqua, "");

            return ketqua;
        }


        public static double LayGiaVe(HtmlAgilityPack.HtmlNode nChuyenBay, int index)
        {
            string giaVe = nChuyenBay.ChildNodes[index].InnerText.Trim();
            if (giaVe.CompareTo(@"Hết vé") != 0)
            {
                giaVe = AirMekongUtils.XoaKyTuCham(giaVe);
                return double.Parse(giaVe);
            }

            return 0;
        }

        public static string XoaKyTuCham(string giaVe)
        {
            int index = giaVe.IndexOf(".");
            while (index != -1)
            {
                giaVe = giaVe.Remove(index, 1);
                index = giaVe.IndexOf(".");
            }
            return giaVe;
        }
    }
}
